package com.gl.glgateway.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 作为jwt过滤
 */
@Component
public class TokenFilter implements GlobalFilter, Ordered {


    private static Logger logger= LoggerFactory.getLogger(TokenFilter.class);


    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //获取token
//        String token = exchange.getRequest().getHeaders().getFirst("token");
//        String url = exchange.getRequest().getURI().getPath();
//        //忽略以下url请求
//        if(url.indexOf("/user-service/login.do") >= 0){
//            return chain.filter(exchange);
//        }
//        ServerHttpResponse response = exchange.getResponse();
//
//        if(StringUtils.isBlank(token)){
//            //没有token
//            logger.error("没有token");
//            return authErro(response,"请登录");
//        }else{
//            //有token
//            boolean verify = TokenUtil.verify(token);
//            if(!verify){
//                logger.error("token过期");
//                return authErro(response,"请重新登录");
//            }
//            return chain.filter(exchange);
//        }

        return chain.filter(exchange);
    }



    @Override
    public int getOrder() {
        return -100;
    }
}
